package com.ls.server.mcp.client;

import cn.hutool.json.JSONUtil;
import com.ls.server.domain.MCPEntity;
import jakarta.annotation.Resource;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author 刘帅
 * @Date: 2025-04-07 21:33
 * @RequestID 需求单号
 * @Version 1.0
 */
@Component
public class CustomMcpToolCallbackProvider {

    @Resource
    private MCPStart mcpStart;

    public ToolCallbackProvider[] getToolCallbackProvider(MCPEntity mcpEntities) {
        List<Map> configList = JSONUtil.toList(mcpEntities.getContent(), Map.class);
        var toolCallbackProviders = configList.stream()
                .map(k -> mcpStart.builderMcpClientSSE(
                        k.get("server").toString(),
                        k.get("url").toString(),
                        mcpEntities.isSync()
                ))
                .toArray(ToolCallbackProvider[]::new);
        return toolCallbackProviders;
    }
}
